In [ ]:

Fahrenheit to Celsius


In [5]:
Fahrenheit = 32.0

Celsius = (Fahrenheit - 32) * 5.0/9.0

print("Temperature: {F} Fahrenheit = {C} Celsius".format(F=Fahrenheit, C=Celsius))


Temperature: 32.0 Fahrenheit = 0.0 Celsius

Celsius to Fahrenheit


In [6]:
Celsius = 100.0

Fahrenheit = 9.0/5.0 * Celsius + 32

print("Temperature: {C} Celsius = {F} Fahrenheit".format(F=Fahrenheit, C=Celsius))


Temperature: 100.0 Celsius = 212.0 Fahrenheit

Plot Example


In [7]:
%matplotlib inline
import matplotlib.pyplot as plt

In [8]:
def C2F(C):
    return 9.0/5.0 * C + 32

C2F(100)


Out[8]:
212.0

In [11]:
x = [C2F(c) for c in range(101)]
x[0:10]


Out[11]:
[32.0, 33.8, 35.6, 37.4, 39.2, 41.0, 42.8, 44.6, 46.4, 48.2]

In [12]:
plt.title("Temperature Conversion")
plt.xlabel("Celsius")
plt.ylabel("Fahrenheit")
plt.plot(x)


Out[12]:
[<matplotlib.lines.Line2D at 0x7fcdbde40c18>]

In [ ]: